package com.lxm.ymcc.custom;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PhoneValidator implements ConstraintValidator<Phone, String> {

    private static final String PHONE_REGEX = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0-9]))\\d{8}$";


    public void initialize(Phone constraint) {
    }

    public boolean isValid(String value, ConstraintValidatorContext context) {
        Pattern compile = Pattern.compile(PHONE_REGEX);
        Matcher matcher = compile.matcher(value);

        return matcher.matches();
    }
}
